<?php
/**
 * 后台首页
 * @author Administrator
 *
 */
class index extends CControllerManageBase{
	
	public function show()
	{
		$this->render("index/index",array(),false);
	}
	
	public function top()
	{
		$this->render("index/top",array("username"=>$this->_userName),false);
	}
	
	public function menu()
	{
		$userModel = new baseUserModel();

	    //左边菜单
	    $moduleAndGroup = $userModel->selectUserModuleRightVaule($this->_userID);

	    //得到group
	    $groupTemp = array();
	    foreach ($moduleAndGroup as $v)
	    {
	    	if(!array_key_exists($v['group_name'],$groupTemp))
	    	{
	    		$groupTemp[$v['group_name']] = $v['group_sort'];
	    	}
	    }
	    asort($groupTemp);
	    $groupAndModule = array();
	    foreach($groupTemp as $k=>$v)
	    {
	    	if(!$k)
	    	{
	    		continue;
	    	}
	    	$tempModule = array();
	    	$tempModuleSort = array();
	    	foreach($moduleAndGroup as $mg)
	    	{
	    		if($mg['group_name']==$k && $mg["is_show"]==1)
	    		{
	    			$tempModule[]=array('module_name'=>$mg['module_name'],'url'=>$mg['url'],'moduleSort'=>$mg['module_sort']);
	    			$tempModuleSort[]=$mg['module_sort'];
	    		}
	    	}
	    	
	    	if($tempModule)
	    	{
		    	asort($tempModuleSort);
		    	array_multisort($tempModuleSort,SORT_ASC,$tempModule);
		    	$groupAndModule[$k]=$tempModule;
	    	}
	    }

		$this->render("index/menu",array("menus"=>$groupAndModule),false);
	}
	
	public function drag()
	{
		$this->render("index/drag",array(),false);
	}

	public function main()
	{
		$this->render("index/main",array(),false);
	}
	
	public function uploadImg()
	{    
    	$strElementId = $this->getRequestData('ElementId', 'get', 'fileImg');
		//$this->_controller
		$tempFile = $_FILES[$strElementId];
		
		if($tempFile["error"]==UPLOAD_ERR_INI_SIZE || $tempFile["error"]==UPLOAD_ERR_FORM_SIZE)
		{
			$this->returnMsg("图片超出系统限制.",0);
			//$this->uploadErr($unid,$msgInfo["midpromotion_uploadFile"]["sys_size_error"]);
		}
		else if($tempFile["error"]==UPLOAD_ERR_PARTIAL || $tempFile["error"]==UPLOAD_ERR_NO_FILE )
		{
			$this->returnMsg("图片上传失败,可能是网络原因,请重试.",0);
			//$this->uploadErr($unid,$msgInfo["midpromotion_uploadFile"]["no_file_error"]);
		}

		//判断文件大小
		$fileSize = $tempFile['size'];
		if ($fileSize>Config::get("uploadImgSize")*1024)
		{
			$this->returnMsg("图片不能超过500KB.",0);
			exit;
	    }
	    
	    $dir = $this->getRequestData("dir","get","images");
	    
	    //获取上传图片信息
                $tempFileName = $tempFile['tmp_name'];

		$fileName = $tempFile['name'];

		if(!CCommon::getImageInfo($tempFileName))
		{
			@unlink($tempFileName); //不是图片则删除
			$this->returnMsg("图片格式不正确，只支持jpg,jpeg,png,gif格式.",0);
			//$this->uploadErr($unid,$msgInfo["midpromotion_uploadFile"]["ex_error"]);
		}
		$iNeedDate = $this->getRequestData('needdate', 'get', 0);
                
		$filePath = "uploadfile/".$dir."/";
		if($iNeedDate){
			$filePath .= date("Ymd")."/";
		}
		
		if(!is_dir($filePath))
		{
	    	mkdir($filePath,0644,true);
		}

	    $pathParts = pathinfo($fileName);
	    
	    $file_ext = $pathParts['extension'];
	    
	    $newFileName = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
	    
		//获取新图片路径和文件名
		$newFile = $filePath.$newFileName;//$this->getNewPicPath($fileName,$filePath);
		
		$return = move_uploaded_file($tempFileName,$newFile);
		
		if(!$return)
		{
			$this->returnMsg("图片上传失败，请重试.",0);
		}
		
		$this->returnMsg("/".$newFile,1);
	}
	
	private $_province_city = array();
	private $_city_area = array();
	
	public function test()
	{
		$type = $this->getRequestData("t"); 
		
		if(!isset($_SESSION["s"]) || isset($_GET["reset"]))
		{
			$_SESSION["s"] = 0;
		}
		
		switch($type)
		{
			case 'community':
				$this->generateCommunity();
				break;
			case 'owner':
				$this->generateOwner();
				break;
			case 'shop':
				$this->generateShop();
				break;
			case 'ownershop':
				$this->generateOwnerShop();
				break;
			case 'integralChange':
				$this->generateIntegralchange();
				break;
			case "supplier":
				$this->generateSupplier();
				break;
			case 'integralChangeReduce':
				$this->generateIntegralchangeReduce();
				break;
			case 'integralChangeCancel':
				$this->generateIntegralchangeCancel();
				break;
		}
		
		
		$this->setMenu("测试数据生成");
		$this->render("test");
	}
	
	/**
	 * 生成社区信息
	 */
	private function generateCommunity()
	{
		$obj = new communityModel();
		
		$count = $obj->getCountByWhere("del_flag=0");
		
		if($count>=100000)
		{
			echo $count;
			exit;
		}
		
		$this->setArea();
		
		$modelInfo = array();

		$startIndex = $_SESSION["s"];

		//$s_time = time();
		$obj->beginTransaction();
		for($i=$startIndex;$i<$startIndex+100;$i++)
		{
			$modelInfo["community_name"] = "社区".$i;
			$areaInfo = $this->generateArea();
			if(count($areaInfo)!=3)
			{
				continue;
			}
			$modelInfo["province"] = $areaInfo[0];
			$modelInfo["city"] = $areaInfo[1];
			$modelInfo["area"] = $areaInfo[2];
			$modelInfo["address"] = "社区".$i."的地址";
			$modelInfo["contact"] = $this->generateNum(4);
			$modelInfo["phone"] = $this->generatePhone();
			$modelInfo["postcode"] = $this->generateNum(6);
			$modelInfo["summary"] = "社区".$i."的简介";
			$modelInfo["create_time"] = $this->generateDate();
			//var_dump($modelInfo);
			$obj->insert($modelInfo);
		}
		
		$obj->commit();
		$_SESSION["s"] = $i;;
		
		echo $i;

		//$e_time = time();
		
		//var_dump($e_time-$s_time);
		exit;
	}
	
	/**
	 * 生成业主信息
	 */
	private function generateOwner()
	{
		$ownerModel = new ownerModel();
		
		$count = $ownerModel->getCountByWhere("del_flag=0");
		
		if($count>=100000)
		{
			echo $count;
			exit;
		}
		
		$modelInfo = array();

		$cList = $ownerModel->selectDataSetByWhere("T_COMMUNITY SAMPLE(1)","community_id",array(),"del_flag=0");

		$c=count($cList);
		
		$cardList = array();
		
		if(isset($_SESSION["card_list"]))
		{
			$cardList = $_SESSION["card_list"];
		}
		
		$cID = 0;
		$ownerModel->beginTransaction();
		$temp = "";
		
		$startIndex = $_SESSION["s"];
		
		if($startIndex==0)
		{
			$startIndex = 100000;
		}
		
		for($i=$startIndex;$i<$startIndex+1000;$i++)
		{
			$temp = "";
			
			for($k=0;$k<12-strlen($i);$k++)
			{
				$temp .="0";
			}
			
			if(array_key_exists($i, $cardList))
			{
				echo -1;exit;
			}
			
			$cardList[$temp] = 1;
			
			$modelInfo["main_card"] = $this->generateNum(16);
			$modelInfo["supplementary_card"] = $temp.$i;
			$modelInfo["user_name"] = $i;
			$modelInfo["create_time"] = $this->generateDate();
			$modelInfo["owner_name"] = $this->generateNum(4);;
			$modelInfo["phone"] = $this->generatePhone();
			$modelInfo["id_card"] = $this->generateNum(18);
			if($c>=1000 || $i-$startIndex<$c)
			{
				$temp = $i-$startIndex;
			}
			else{
				$temp = rand(0,$c-1);
			}
			
			
			$cID = $cList[$temp]["community_id"];
			
			$modelInfo["community_id"] = $cID;
			$modelInfo["address"] = "业主地址";
			$modelInfo["remark"] = "业主备注";
			//$pwdStr = substr($modelInfo["id_card"],strlen($modelInfo["id_card"])-6);
			$modelInfo["user_pwd"] = CCommon::pwdMd5("123456");
			$modelInfo["pay_pwd"] = CCommon::pwdMd5("000000");
			$modelInfo["first_login"] = 0;

			$ownerModel->insert($modelInfo);
		}
		
		$ownerModel->commit();
		$_SESSION["s"] = $i;
		$_SESSION["card_list"] = $cardList;
		
		echo $i-100000;

		exit;
	}
	
	/**
	 * 生成商户信息
	 */
	private function generateShop()
	{
		$shopModel = new shopModel();
		
		$count = $shopModel->getCountByWhere("del_flag=0");
		
		if($count>=100000)
		{
			echo $count;
			exit;
		}
		
		$modelInfo = array();
		$startIndex = $_SESSION["s"];
		
		if($startIndex==0)
		{
			$startIndex = 100000;
		}

		$cList = $shopModel->selectDataSetByWhere("T_COMMUNITY SAMPLE(2)","community_id",array(),"del_flag=0");

		$c=count($cList);
		
		$cID = 0;
		$shopModel->beginTransaction();
		
		$rnum = 0;
		for($i=$startIndex;$i<$startIndex+500;$i++)
		{
			$rnum = rand(5, 15);
			$modelInfo["user_name"] = "s".$i;
			$modelInfo["create_time"] = $this->generateDate();
			$modelInfo["shop_name"] = $this->generateCh($rnum);
			$modelInfo["phone"] = $this->generatePhone();
			
			$rnum = $rnum-2;
			$modelInfo["shop_simple_name"] = $this->generateCh($rnum);
			$modelInfo["back_account"] = $this->generateNum(16);
			$modelInfo["contact"] = $this->generateNum(4);
			$modelInfo["mail"] = $this->generateMail();
			$modelInfo["qq"] = $this->generateQQ();
			
			$rnum = rand(10, 50);
			$modelInfo["bus_content"] =$this->generateCh($rnum);
			$modelInfo["remark"] = $this->generateCh($rnum);
			$modelInfo["bus_license_pic"] = "";
			
			$modelInfo["user_pwd"] = CCommon::pwdMd5("000000");
			$modelInfo["pay_pwd"] = $modelInfo["user_pwd"];
			
			$sid = $shopModel->insert($modelInfo);
			
			$rnum = rand(2, 10);
			
			$rand_keys = array_rand($cList, $rnum);
			
			for($j=0; $j<$rnum; $j++)
			{
				$temp = $rand_keys[$j];
				if(isset($cList[$temp]))
				{
					$cid = $cList[$temp]["community_id"];
					$shopModel->addShopCommunity($sid, $cid);
				}
				else{
					var_dump($rand_keys);
					var_dump($j);
					var_dump($rnum);
					var_dump($temp);
				}
			}

			$rnum = rand(1, 7);
			$scInfo["shop_id"] = $sid;
			$scInfo["p_name"] = $modelInfo["shop_name"];
			$scInfo["pic_path"] = "/images/o_list_demo.jpg";
			$scInfo["p_type"] = $rnum;
			$scInfo["create_time"] = $modelInfo["create_time"];;
			$scModel = new shopProductModel();
			$scModel->insert($scInfo);
		}
		
		$shopModel->commit();
		$_SESSION["s"] = $i;
		
		echo $i-100000;

		//$e_time = time();
		
		//var_dump($e_time-$s_time);
		exit;
	}
	
	/**
	 * 生成业主商户对应关系
	 */
	private function generateOwnerShop()
	{
		$ownerModel = new ownerShopModel();
		
		$oList = $ownerModel->selectDataSetByWhere("t_owner SAMPLE(0.1)","distinct owner_id",array(),"del_flag=0");
		
		$c=count($oList);
		
		$cID = 0;
		
		$temp = "";
		
		$startIndex = $_SESSION["s"];
		
		if($startIndex==0)
		{
			$startIndex = 1;
		}
		$rnum = 0;
		$discount = 0;
		
		$discount_2_arr = array("0.5","0.55","0.6","0.65","0.7","0.75","0.8","0.85","0.88","0.9","0.91","0.95");

		$ownerModel->beginTransaction();
		
		for($i=$startIndex;$i<$startIndex+100;$i++)
		{
			$k = rand(5, 20);
			
			$rand_keys = array_rand($oList, $k);
				
			for($j=0; $j<$k; $j++)
			{
				$modelInfo = array();
				$rnum = $rand_keys[$j];

				$ownerID = $oList[$rnum]["owner_id"];
				//echo $i."-".$ownerID."<br />";
				$modelInfo["owner_id"] = $ownerID;
				$modelInfo["shop_id"] = $i;
				$modelInfo["balance"] = 0;
				
				$rnum = rand(1, 2);
				$modelInfo["c_discount_type"] = $rnum;
				
				if($rnum==1)
				{
					$discount = rand(10, 100);
				}else {
					$discount = $this->getRandFromArr($discount_2_arr);
				}
				$modelInfo["c_discount"] = $discount;
				$modelInfo["create_time"] = $this->generateDate();
			
				$ownerModel->insert($modelInfo);
			}
		}
		
		$ownerModel->commit();
		$_SESSION["s"] = $i;
		
		echo $i;
		
		exit;
	}
	
	/**
	 * 生成增加积分交易记录
	 */
	private function generateIntegralchange()
	{
		$startIndex = $_SESSION["s"];
		
		$ownerID = 0;
		$discountType = 0;
		$balance = 0;
		$discount = 0;
		$rnum = 0;
		$discount_2_arr = array("0.5","0.55","0.6","0.65","0.7","0.75","0.8","0.85","0.88","0.9","0.91","0.95");
		$costType = $this->getRequestData("type","get");
		
		$ownerShopModel = new ownerShopModel();

		$oList = $ownerShopModel->selectDataSetByWhere("t_owner SAMPLE(1)","owner_id,supplementary_card,balance",array(),"del_flag=0");

		$sList = $ownerShopModel->selectDataSetByWhere("t_shop SAMPLE(1)","distinct shop_id",array(),"del_flag=0");

		$oc = count($oList);
		$sc = count($sList);
		
		$o_rand_keys = array_rand($oList, 100);
		$s_rand_keys = array_rand($sList, 100);
		
		$ownerModel = new ownerModel();
		$ownerShopModel->beginTransaction();
		
		for($i=0;$i<100;$i++)
		{
			$rnum = $o_rand_keys[$i];
			
			$ownerInfo = $oList[$rnum];
			$ownerID = $ownerInfo["owner_id"];
			$rnum = $s_rand_keys[$i];
			$shopID = $sList[$rnum]["shop_id"];

			$ownerShopRe = $ownerShopModel->selectByWhere(
			"t_owner_shop",
			"os_id,owner_id,shop_id,balance,owner_card_status,c_discount_type,c_discount",
			array("owner_id"=>$ownerID,"shop_id"=>$shopID),"del_flag=0");

			if($ownerShopRe)
			{
				$discountType = $ownerShopRe["c_discount_type"];
			}
			else{
				$discountType = rand(1, 2);
			}
			
			if($discountType==1)
			{
				$discount = rand(10, 100);
			}else {
				$discount = $this->getRandFromArr($discount_2_arr);
			}
			
			$rnum = rand(10,100);
			$balance = $rnum*10;
			
			$c_id = $ownerShopModel->addBalance($ownerInfo,$ownerShopRe,$ownerID,$shopID,$balance,$discountType,$discount,true);
		}
		
		$ownerShopModel->commit();
		$_SESSION["s"] = $startIndex+100;
		
		echo $startIndex+100;
		
		exit;
	}
	
	/**
	 * 生成商户供应商
	 */
	private function generateSupplier(){
		$startIndex = $_SESSION["s"];
		
		$generateNum = 1000;
		$rnum = 0;
		$modelInfo = array();

		$supplierModel = new supplierModel();

		$sList = $supplierModel->selectDataSetByWhere("t_shop SAMPLE(1.5)","distinct shop_id",array(),"del_flag=0");

		$sc = count($sList);
		
		$s_rand_keys = array_rand($sList, $generateNum);
		
		if($generateNum==1)
		{
			$s_rand_keys = array($s_rand_keys);
		}

		$supplierModel->beginTransaction();
		
		for($i=0;$i<$generateNum;$i++)
		{
			$modelInfo = array();
			$rnum = $s_rand_keys[$i];
			
			$shopID = $sList[$rnum]["shop_id"];
			
			$rnum = rand(5, 15);
			
			$modelInfo["shop_id"] = $shopID;
			$modelInfo["s_name"] = $this->generateCh($rnum);
			$modelInfo["s_phone"] = $this->generatePhone();
			
			$rnum = rand(2, 4);
			$modelInfo["s_person"] = $this->generateCh($rnum);
			$modelInfo["back_name"] = $this->generateBank();
			$modelInfo["back_account"] = $this->generateNum(18);
			
			$rnum = rand(3, 20);
			$modelInfo["remark"] = $this->generateCh($rnum);
			$modelInfo["create_time"] = $this->generateDate();
				
			$supplierModel->insert($modelInfo,false);
		}
		
		$supplierModel->commit();
		$_SESSION["s"] = $startIndex+$generateNum;
		
		echo $startIndex+$generateNum;
		
		exit;
	}

	/**
	 * 生成扣减积分交易记录
	 */
	private function generateIntegralchangeReduce()
	{
		$startIndex = $_SESSION["s"];
	
		$generateNum = 100;
		$ownerID = 0;
		$discountType = 0;
		$balance = 0;
		$discount = 0;
		$rnum = 0;
		//$discount_2_arr = array("0.5","0.55","0.6","0.65","0.7","0.75","0.8","0.85","0.88","0.9","0.91","0.95");
		
		$ownerShopModel = new ownerShopModel();

		$osList = $ownerShopModel->selectDataSetByWhere("t_owner_shop SAMPLE(0.2)","os_id,owner_id,shop_id,balance,c_discount_type,c_discount",array(),"balance>0");
	
		//$sList = $ownerShopModel->selectDataSetByWhere("t_shop SAMPLE(1)","distinct shop_id",array(),"del_flag=0");
	
		$osc = count($osList);
		//$sc = count($sList);

		$os_rand_keys = array_rand($osList, $generateNum);
		
		if($generateNum==1)
		{
			$os_rand_keys = array($os_rand_keys);
		}
		
		$ownerShopModel->beginTransaction();
	
		for($i=0;$i<$generateNum;$i++)
		{
			$rnum = $os_rand_keys[$i];
			
			$ownerShopInfo = $osList[$rnum];
			
			$ownerID = $ownerShopInfo["owner_id"];
				
			$shopID = $ownerShopInfo["shop_id"];

			$ownerInfo = $ownerShopModel->selectByWhere(
			"t_owner","supplementary_card,balance",
				array("owner_id"=>$ownerID));

			$discountType = $ownerShopInfo["c_discount_type"];
			$balance = $ownerShopInfo["balance"];

			if($balance>1)
			{
				$balance = floor($balance);//余额
				
				$discount = rand(1, $balance); //本次扣减积分
			}
			else{
				$discount = $balance;
			}

			$s_discount = $discount;//本次实际扣减积分
			if($discountType==2)
			{
				$s_discount = $discount*$ownerShopInfo["c_discount"]; 
			}

			$supplierList = $ownerShopModel->selectDataSetByWhere(
				"t_supplier",
				"s_id",
				array(),
				"shop_id=".$shopID
			);
			
			$s_id = 0;
			if($supplierList)
			{
				$temp = $this->getRandFromArr($supplierList);
				$s_id = $temp["s_id"];
			}
			
			$c_id = $ownerShopModel->reduceBalance($ownerInfo,$ownerShopInfo,$ownerID,$shopID,$discount,$s_discount,$s_id,true);
		}

		$ownerShopModel->commit();
		$_SESSION["s"] = $startIndex+$generateNum;
	
		echo $startIndex+$generateNum;

		exit;
	}
	
	/**
	 * 生成撤销积分交易记录
	 */
	private function generateIntegralchangeCancel()
	{
		$startIndex = $_SESSION["s"];
	
		$generateNum = 100;
		$rnum = 0;

		$ownerShopModel = new ownerShopModel();
	
		$icList = $ownerShopModel->selectDataSetByWhere("T_INTEGRAL_CHANGE SAMPLE(1)","*",array(),"is_cancel=0");

		$icc = count($icList);
		$os_rand_keys = array_rand($icList, $generateNum);
	
		$ownerShopModel->beginTransaction();
	
		for($i=0;$i<$generateNum;$i++)
		{
			$rnum = $os_rand_keys[$i];
			$c_id = $ownerShopModel->cancelPay($icList[$rnum],true);
		}
	
		$ownerShopModel->commit();
		$_SESSION["s"] = $startIndex+$generateNum;
	
		echo $startIndex+$generateNum;
	
		exit;
	}
	
	private function showMis()
	{
		$t1 = microtime(true);
		echo $t1*1000;
		echo "<br />";
	}
	
	/**
	 * 随机生成汉字
	 * @param int $l
	 */
	private function generateCh($l)
	{
		$string = '';
		for($i=0;$i<$l;$i++) {
			$string .= chr(rand(0xB0,0xD7)).chr(rand(0xA1,0xDE));
		}
			
		$string = iconv("gb2312","utf-8",$string);
		return $string;
	}
	
	private function setArea()
	{
		$obj = new communityModel();
		
		$temp = $obj->selectDataSetByWhere("t_province_city");
		
		$this->_province_city = array();
		foreach($temp as $item)
		{
			$this->_province_city[$item["province"]][] = $item["city"];
		}
		
		$temp = $obj->selectDataSetByWhere("t_city_area");
		$this->_city_area = array();
		foreach($temp as $item)
		{
			$this->_city_area[$item["city"]][] = $item["area"];
		}
	}
	
	/**
	 * 随机数字字符串
	 * @param int $l 字符串长度
	 */
	private function generateNum($l)
	{
		$str = "";
		for($i=0;$i<$l;$i++)
		{
			$str .= rand(0, 9)."";
		}
		
		return $str;
	}
	
	/**
	 * 随机qq
	 */
	private function generateQQ()
	{
		$str = "";
		$r = rand(6, 12);
		
		return $this->generateNum($r);
	}
	
	/**
	 * 随机邮箱
	 * @return string
	 */
	private function generateMail()
	{
		$str = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,o,v,w,x,y,z,_";
		$mailArr = array("126.com","163.com","sina.com","yahoo.com","yahoo.com.cn","yahoo.cn","sohu.com","tom.com","hotmail.com","139.com","qq.com");
		
		$mailExt = $this->getRandFromArr($mailArr);
		
		$temp = "";
		$r = rand(3, 20);
		
		if($mailExt!="qq.com")
		{
			$a = explode(",",$str);
			
			for($i=0;$i<$r;$i++)
			{
				$temp .= $this->getRandFromArr($a);
			}
		}
		else{
			$temp = $this->generateNum($r);
		}
	
		return $temp."@".$mailExt;
	}
	
	/**
	 * 随机用户名
	 * @param unknown_type $l
	 * @return Ambigous <string, array>
	 */
	private function generateUserName($l)
	{
		$str = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,o,v,w,x,y,z,!,@,#,$,%,^,&,*,(,),_,+,-,=";
		$a = explode(",",$str);
		$temp = "";
		for($i=0;$i<$l;$i++)
		{
			$temp .= $this->getRandFromArr($a);
		}
		
		return $temp;
	}
	
	/**
	 * 返回一个银行
	 */
	private function generateBank()
	{
		$bankList = array(
			"中国银行",
			"工商银行",
			"农业银行",
			"建设银行",
			"交通银行",
			"招商银行",
			"深圳发展银行",
			"浦发银行",
			"民生银行",
			"华夏银行",
			"兴业银行",
			"中信银行",
			"光大银行",
			"广发银行",
			"恒丰银行"
		);
		
		return $this->getRandFromArr($bankList);
	}
	
	/**
	 * 从数组随机获取一个值
	 * @param array $arr
	 */
	private function getRandFromArr($arr)
	{
		$l = count($arr)-1;
		
		$l = rand(0,$l);
		
		return $arr[$l];
	}
	
	/**
	 * 随机生成电话号码
	 */
	private function generatePhone()
	{
		$l_phone_arr = array("130","131","132","134","136","138","139","150","158","159","180","186","187","188","189");
		
		$l_phone = $this->getRandFromArr($l_phone_arr);
		
		$r_phone = $this->generateNum(8);
		
		return $l_phone."".$r_phone;
	}
	
	/**
	 * 获取随机日期
	 */
	private function generateDate()
	{
		$s_time_str = strtotime('2013-06-01');
		
		$add_time = rand(1000,10000000);
		
		$s_time_str = $s_time_str+$add_time;
		return date("Y-m-d H:i:s",$s_time_str);
	}
	
	private function generateArea()
	{
		$provinceArr = array("北京市","天津市","河北省","山西省","内蒙古","辽宁省","吉林省","黑龙江省","上海市","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西","海南省","重庆市","四川省","贵州省","云南省","西藏","陕西省","甘肃省","青海省","宁夏","新疆");
		
		$province = $this->getRandFromArr($provinceArr);
		//var_dump($province);
		$city_list = $this->_province_city[$province];
		
		$city = $this->getRandFromArr($city_list);
		//var_dump($city);
		
		$area_list = array();
		
		if(isset($this->_city_area[$city]))
		{
			$area_list = $this->_city_area[$city];
			$area = $this->getRandFromArr($area_list);
		
			return array($province,$city,$area);
		}
		
		return $this->generateArea();
	}
	
	/**
	 * 上传图片后返回到客户端
	 * @param string $msg 提示信息
	 * @param int $flag 1成功标记，0失败
	 */
	private function returnMsg($url,$flag)
	{
		$strSrcId = $this->getRequestData('srcid', 'get', 'imgContent');
		$strPathId = $this->getRequestData('pathid', 'get', 'hidImgPath');
		if($flag==1)
		{
			echo "<script>parent.document.getElementById('{$strSrcId}').src='".$url."'; parent.document.getElementById('{$strPathId}').value='".$url."';parent.validFileUpload();</script>";
		}
		else
		{
			echo "<script>alert('".$url."');</script>";
		}
		exit;
	}
}